package cn.edu.jxau.test;

import java.util.ArrayList;
import java.util.List;

/**
 * 欧几里得算法
 * @author 付大石
 */
public class Main {

    public static void main(String[] args) {
        
        System.out.println(gcd(4,12));
        System.out.println(gcd(12,4));
        System.out.println(gcd(5,12));
        System.out.println(gcd(12,5));
    }
    
    private static int gcd(int p, int q) {

        if (q == 0) {
            return p;
        }
        int r = p % q;
        return gcd(q, r);
    }
    
//    private static int gcd(int p, int q) {
//        while(q != 0) {
//            
//            int r = p % q;
//            p = q;
//            q = r;
//        }
//        return p;
//    }
}
